import React from 'react';
import { connect } from 'dva';
import moment from 'moment';
import Comp from '../component/Comp';

class ResaleWarn extends React.Component {
  constructor() {
    super();
    this.state = {
      resaleArr: [],
    };
  }
  componentDidMount() {
    const { dispatch } = this.props;
    let params;
    if (localStorage.getItem('antd-pro-superMan') == 'true') {
      dispatch({
        type: 'OperatePlatformM/storeSuper',
        payload: {},
        callback: (res) => {
          params = {
            requestDate: moment().format('YYYY-MM-DD'),
            currentPage: 1,
            numInPage: 10,
            tenant: res.length ? res[0].value : '',
          };
          this.qxFn(params);
        },
      });
    } else {
      params = {
        requestDate: moment().format('YYYY-MM-DD'),
        currentPage: 1,
        numInPage: 10,
      };
      this.qxFn(params);
    }
  }
  qxFn = (params) => {
    const { dispatch } = this.props;
    //当日债回售提醒
    dispatch({
      type: 'OperatePlatformM/queryBondsSoldBackList',
      payload: params,
      callback: (res) => {
        if (res?.list?.length) {
          let arrs = res.list;
          for (var i = 0; i < arrs.length; i++) {
            arrs[i].name = arrs[i].tradingname;
            arrs[i].code = arrs[i].tradingcode;
          }
          this.setState({
            resaleArr: arrs,
          });
        } else {
          this.setState({
            resaleArr: [],
          });
        }
      },
    });
  };
  render() {
    const { loading } = this.props;
    return <Comp title='回售登记提醒' hasMore={true} refs='swiper-containerResale' refsPag='swiper-pagination' loading={loading} slideArr={this.state.resaleArr}></Comp>;
  }
}
export default connect(({ OperatePlatformM, loading }) => ({ OperatePlatformM, loading: loading.effects['OperatePlatformM/queryBondsSoldBackList'] }))(ResaleWarn);
